package net.happy2v.file.server.test.file.intrfc;

import net.ib.mn.protocol.File.DownloadReq;
import net.ib.mn.protocol.File.DownloadRes;
import net.ib.mn.protocol.File.UploadReq;
import net.ib.mn.protocol.File.UploadRes;
import net.ib.mn.protocol.File.ValidateDownloadReq;
import net.ib.mn.protocol.File.ValidateDownloadRes;
import net.ib.mn.protocol.File.ValidateSliceNoReq;
import net.ib.mn.protocol.File.ValidateSliceNoRes;
import net.ib.mn.protocol.File.ValidateUploadReq;
import net.ib.mn.protocol.File.ValidateUploadRes;
import net.ib.rpc.channel.RpcChannelImpl;
import net.ib.rpc.controller.DefaultRpcControllerImpl;
import net.ib.rpc.method.MethodInfos;

import org.jboss.netty.channel.Channel;

import com.google.protobuf.Descriptors.MethodDescriptor;
import com.google.protobuf.Message;
import com.google.protobuf.RpcCallback;
import com.google.protobuf.RpcController;

public class FileServiceInterface{

	private net.ib.mn.protocol.FileServices.File file = null;

	public FileServiceInterface(Channel channel, MethodInfos services) {
		this.file = net.ib.mn.protocol.FileServices.File.newStub(new RpcChannelImpl(
				channel));
	}

	public void callMethod(MethodDescriptor method, Message request,
			RpcCallback<Message> done) {
		System.out.println("callMethod");
		file.callMethod(method, null, request, done);
	}

	public void validateUpload(ValidateUploadReq request) {
		System.out.println("validateUpload");

		RpcCallback<ValidateUploadRes> done = new RpcCallback<ValidateUploadRes>() {
			@Override
			public void run(ValidateUploadRes res) {
				System.out.println("uploadRes : " + res);
			}
		};
		file.validateUpload(new DefaultRpcControllerImpl(), request, done);
	}

	public void validateUpload(ValidateUploadReq request,
			RpcCallback<ValidateUploadRes> done) {
		System.out.println("validateUpload");
		file.validateUpload(new DefaultRpcControllerImpl(), request, done);
	}

	public void validateUpload(RpcController controller,
			ValidateUploadReq request, RpcCallback<ValidateUploadRes> done) {
		System.out.println("validateUpload");
		file.validateUpload(controller, request, done);
	}

	public void upload(UploadReq request) {
		System.out.println("upload");
		RpcCallback<UploadRes> done = new RpcCallback<UploadRes>() {
			@Override
			public void run(UploadRes res) {
				System.out.println("uploadRes : " + res);
			}
		};
		file.upload(new DefaultRpcControllerImpl(), request, done);
	}

	public void upload(UploadReq request, RpcCallback<UploadRes> done) {
		System.out.println("upload");
		file.upload(new DefaultRpcControllerImpl(), request, done);
	}

	public void upload(RpcController controller, UploadReq request,
			RpcCallback<UploadRes> done) {
		System.out.println("upload");
		file.upload(controller, request, done);
	}

	public void validateDownload(ValidateDownloadReq request,
			RpcCallback<ValidateDownloadRes> done) {
		System.out.println("validateDownload");
		file.validateDownload(null, request, done);
	}

	public void validateSliceNo(ValidateSliceNoReq request,
			RpcCallback<ValidateSliceNoRes> done) {
		System.out.println("validateSliceNo");
		file.validateSliceNo(null, request, done);
	}

	public void download(DownloadReq request, RpcCallback<DownloadRes> done) {
		System.out.println("download");
		file.download(null, request, done);
	}

}
